var end = false;
var page = 0;
var loading = false; // 状态标记
$(function() {
	$('.weui_tab_bd').css('height', $(window).height() - 50);
	$("#model").click();
})

function list(classid, obj) {
	$(".weui_navbar a").removeClass("weui_bar_item_on");
	$(obj).addClass("weui_bar_item_on");
	if(classid == 9) {
		$("#articledetail1").show();
		$("#brandlist").hide();
		$("#articledetail2").hide();	
		changeMember(1);
	} else if (classid == 8) {
		$("#articledetail1").hide();
		$("#brandlist").show();
		$("#articledetail2").hide();
	} else {
		$("#articledetail1").hide();
		$("#brandlist").hide();
		$("#articledetail2").show();
		$("#articleClassId").val(classid);
		changeMember(3);
	}
}

function loadData(type) {
	if (loading)
		return false;
	if (end) {
		return false;
	}
	loading = true;
	$("#loading-div").show();
	$.ajax({
		url : appPath + '/article/list/' + $("#articleClassId").val() + '/' + page + '.html',
		dataType : 'html',
		data : {
		},
		success : function(result) {
			var over = $("#over").val();
			if (over) {
				end = true;
			} else {
				page = page + 1;
				if (type) {
					$(".weui_panel_bd").html(result);
				} else {
					$(".weui_panel_bd").append(result);
				}
			}
			$("#loading-div").hide();
			loading = false;
		},
		error : function(XMLHttpRequest, textStatus, errorThrown) {
			$.hideLoading();
			$("#loading-div").hide();
			$.alert("系统异常，请重试");
		}
	});
}
function detail(id) {
	recordScene();
	window.location.href = appPath + "/article/detail/" + id + ".html";
}
/**
 * 记录现场
 */
function recordScene(){
	var bodyContent = $("body").html();
	var contentScrollTop= $("#div1").scrollTop();
	try{
		//记录内容
		sessionStorage.setItem("goodsListContent",bodyContent);
		//记录滚动
		sessionStorage.setItem("goodsListScrollTop",contentScrollTop);
		//记录返回flag
		sessionStorage.setItem("sceneFlag","1");
	}catch(e){
		
	}
}
/**
 * 还原现场
 */
function revertScene(){
	var sceneFlag = 0;
	var notDetailBackFlag = 0;
	try {
		sceneFlag = sessionStorage.getItem("sceneFlag");
		notDetailBackFlag = sessionStorage.getItem("notDetailBackFlag");
	} catch (e) {

	}
	if ("1" == sceneFlag && "1" != notDetailBackFlag) {
		var bodyContent = sessionStorage.getItem("goodsListContent");
		var contentScrollTop = sessionStorage.getItem("goodsListScrollTop");
		$("body").html(bodyContent);
	}
	try {
		sessionStorage.removeItem("sceneFlag");
		sessionStorage.removeItem("notDetailBackFlag");
	} catch (e) {

	}
}

function changeMember(num){
	var a = 0, b = 0;
	if (num < 3) {
		a = 1;
		b = 3;
	} else {
		a = 3;
		b = 5;
	}
	for (var i = a; i < b; i++) {
		if (i == num) {
			$('#article' + i).show();
			$('#member' + i).css('background-color', 'white');
			$('#member' + i).css('border', '1px solid #fdc640');
			$('#member' + i).css('color', '#fdc640');
			$('#member' + i).css('line-height', '40px');
		} else {
			$('#article' + i).hide();
			$('#member' + i).css('background-color', 'white');
			$('#member' + i).css('border', '#666');
			$('#member' + i).css('color', '#666');
			$('#member' + i).css('line-height', '40px');
		}
	}
}